//
//  FansTrdFrameModel.m
//  LiveStar
//
//  Created by 漪珊 on 2017/4/24.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "FansTrdFrameModel.h"
#import "YBPictureView.h"
#import "FansTrdModel.h"

@implementation FansTrdFrameModel
- (void)setTrendModel:(FansTrdModel *)trendModel {
    _trendModel = trendModel;
    //正文
    CGSize maxSize = CGSizeMake(kSCREEN_WIDTH - 30, MAXFLOAT);
    
    NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14], NSForegroundColorAttributeName: [UIColor colorWithWhite:0.263 alpha:1.000]};
    CGSize textSize = [trendModel.c_content boundingRectWithSize:maxSize
                                                   options:NSStringDrawingUsesLineFragmentOrigin
                                                attributes:attributes
                                                   context:nil].size;
    CGSize richTextSize = CGSizeMake(textSize.width, textSize.height + 2);
    self.contentHeight = richTextSize.height;
    //配图
    if (trendModel.pictureArray.count == 1) {
//        NSString *picName = _trendModel.pictureArray.firstObject;
//        [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:picName] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
//            
//        } completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
//            if (image) {
//                UIImage *img = image;
////                float scale = img.size.width/img.size.height;
////                
////                CGFloat picViewW;
////                CGFloat picViewH;
////                
////                CGFloat pictureFixedWidth = (kSCREEN_WIDTH - 2 * 15)/2;
////                CGFloat pictureFixedHeight = pictureFixedWidth * 0.5;
////                
////                if (scale >= 1.0) {
////                    picViewW = pictureFixedWidth;
////                    picViewH = picViewW / scale;
////                } else {
////                    picViewH = pictureFixedHeight;
////                    picViewW = picViewH * scale;
////                }
////                
////                CGSize pictureSize = CGSizeMake(picViewW, picViewH);
////                self.pictureViewFrame = CGRectMake(0, 0, pictureSize.width, pictureSize.height);
////                self.picViewHeight = picViewH;
////                self.cellHeight = 145 + self.contentHeight + self.picViewHeight;
//            }
//        }];
        self.pictureViewFrame = CGRectMake(0, 0, kSCREEN_WIDTH/3, kSCREEN_WIDTH/3);
        self.picViewHeight = kSCREEN_WIDTH/3;
        
    } else if(trendModel.pictureArray.count > 1){
        CGSize picturesSize = [YBPictureView sizeWithPhotosCount:(int)trendModel.pictureArray.count];
        self.pictureViewFrame = CGRectMake(0, 0, kSCREEN_WIDTH - 2 * 15, self.picViewHeight);
        
        self.picViewHeight = picturesSize.height;
    } else {
        self.picViewHeight = richTextSize.height;
    }
    
    
    //cell的高度
    self.cellHeight = 145 + self.contentHeight + self.picViewHeight;
    NSLog(@"####计算的--------%f",self.cellHeight);
    
    //cell的frame
//    self.frame = CGRectMake(0, 0, cellWidth, self.cellHeight);

    
}
@end
